package com.letoken.platform.repo.admin.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.repo.admin.po.AppUserSwapRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.admin.req.user.QueryQuickswapListReq;
import com.letoken.platform.repo.admin.res.user.QueryQuickswapListRes;
import com.letoken.platform.repo.admin.res.user.UpdateDateCapReq;
import com.letoken.platform.repo.app.req.config.QueryHistoryReq;
import com.letoken.platform.repo.app.res.config.QueryHistoryRes;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Le账户-用户闪兑订单表 Mapper 接口
 * </p>
 *
 * @author 作者
 * @since 2022-12-12
 */
public interface AppUserSwapRecordMapper extends BaseMapper<AppUserSwapRecord> {

    Page<QueryQuickswapListRes> queryQuickswapList(@Param("page") Page<QueryQuickswapListRes> page, @Param("req") QueryQuickswapListReq req);


    //todo 只显示上线后的记录
    Page<QueryHistoryRes> queryQuickSwapHistory(@Param("page") Page<QueryHistoryRes> page, @Param("req") QueryHistoryReq req, @Param("userId") Integer userId);


    @Select("select w.available_balance availableBalance,t.amount amount,t.user_id userId from app_user_wallet w,(select user_id,sum(to_amount) amount from app_user_swap_record where from_type =2 and to_type=4 GROUP BY user_id) t where w.token_id=4  and t.user_id=w.user_id and w.available_balance>=t.amount")
    List<UpdateDateCapReq> updateDateCap();
}
